package com.shrct.businessprocess.purchase.impl;

import com.shrct.businessprocess.product.RCProductSpecification;
import com.shrct.businessprocess.product.impl.RCProductSpecificationImpl;
import com.shrct.businessprocess.purchase.RCProductPurchaseRequest;
import com.shrct.businessprocess.purchase.RCProductPurchaseRequestItem;
import com.shrct.businessprocess.purchase.impl.RCProductPurchaseRequestImpl;
import com.shrct.businessprocess.purchase.proxy.RCProductPurchaseRequestItemProxy;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("RCPRODUCTPURCHASEREQUESTITEM_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rcproductpurchaserequestitem")
public class RCProductPurchaseRequestItemImpl extends BaseModelObject implements RCProductPurchaseRequestItem {
  public RCProductPurchaseRequestItemImpl() {
    super();
  }
  
  public RCProductPurchaseRequestItemImpl(final RCProductPurchaseRequest purchaseRequest) {
    super();
    this.purchaseRequest = purchaseRequest;
  }
  
  @JoinColumn(name = "purchaseRequest_id")
  @ManyToOne(targetEntity = RCProductPurchaseRequestImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCProductPurchaseRequest purchaseRequest;
  
  public RCProductPurchaseRequest getPurchaseRequest() {
    return this.purchaseRequest;
  }
  
  public RCProductPurchaseRequestItem setPurchaseRequest(final RCProductPurchaseRequest purchaseRequest) {
    this.purchaseRequest = purchaseRequest;
    return this;			
    
  }
  
  @JoinColumn(name = "productSpec_id")
  @ManyToOne(targetEntity = RCProductSpecificationImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCProductSpecification productSpec;
  
  public RCProductSpecification getProductSpec() {
    return this.productSpec;
  }
  
  public RCProductPurchaseRequestItem setProductSpec(final RCProductSpecification productSpec) {
    this.productSpec = productSpec;
    return this;			
    
  }
  
  private Integer quantity;
  
  public Integer getQuantity() {
    return this.quantity;
  }
  
  public RCProductPurchaseRequestItem setQuantity(final Integer quantity) {
    this.quantity = quantity;
    return this;			
    
  }
  
  public Integer getPassedOrderedQuantity() {
    Integer _totalPassedOrderItemsQuantity = this.purchaseRequest.getTotalPassedOrderItemsQuantity(this.productSpec);
    return _totalPassedOrderItemsQuantity;
  }
  
  public Integer getOrderedQuantity() {
    Integer _totalOrderItemsQuantity = this.purchaseRequest.getTotalOrderItemsQuantity(this.productSpec);
    return _totalOrderItemsQuantity;
  }
  
  public static RCProductPurchaseRequestItem create(final RCProductPurchaseRequest purchaseRequest, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.purchase.RCProductPurchaseRequestItem rCProductPurchaseRequestItem = new com.shrct.businessprocess.purchase.impl.RCProductPurchaseRequestItemImpl(
    	purchaseRequest
    );
    objectFactory.create(rCProductPurchaseRequestItem);
    return rCProductPurchaseRequestItem;			
    
  }
  
  public static RCProductPurchaseRequestItem createRCProductPurchaseRequestItemImpl(final RCProductPurchaseRequest purchaseRequest, final IObjectFactory objectFactory, final Procedure1<RCProductPurchaseRequestItem> init) {
    com.shrct.businessprocess.purchase.RCProductPurchaseRequestItem rCProductPurchaseRequestItem = new com.shrct.businessprocess.purchase.impl.RCProductPurchaseRequestItemImpl(
    	purchaseRequest
    );
    objectFactory.create(rCProductPurchaseRequestItem);
    init.apply(rCProductPurchaseRequestItem);
    
    return rCProductPurchaseRequestItem;			
    
  }
  
  public RCProductPurchaseRequestItemProxy toProxy() {
    com.shrct.businessprocess.purchase.proxy.RCProductPurchaseRequestItemProxy proxy = new com.shrct.businessprocess.purchase.proxy.RCProductPurchaseRequestItemProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
